/**
 * @file poj/1985/main.cpp
 * @brief
 * @see
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @copyright 2022
 * @date 2022/6/23 13:06:23
 **/

#include <bits/stdc++.h>
const int N = 1e6 + 4;
struct Edge {
  int v, w;
};
using namespace std;
int n, m, ans, D[N];
vector<Edge> adj[N];
void dfs(int u, int fa) {
  int &d = D[u], d1 = 0;  // 最短路长度，次短路长度
  d = 0;
  for (const auto& [v, w] : adj[u]) {
    if (v == fa) continue;
    dfs(v, u);
    int nd = w + D[v];
    if (nd > d)
      d1 = d, d = nd;
    else if (d > d1)
      d1 = nd;
  }
  ans = max(ans, d + d1);
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int u, v, w;
    string S;
    cin >> u >> v >> w >> S;
    adj[u].push_back({v, w});
    adj[v].push_back({u, w});
  }
  ans = -1;
  dfs(1, -1);
  cout << ans << endl;
}
